package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.common.enums.PublishStatusEnum;
import com.ibeeking.found.msg.rest.service.ISmsTemplateService;
import com.ibeeking.found.msg.service.common.param.SmsTemplateParam;
import com.ibeeking.found.msg.service.common.query.SmsTemplateQuery;

import com.ibeeking.found.msg.service.common.vo.SmsTemplateParamVO;
import com.ibeeking.found.msg.service.common.vo.SmsTemplateVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName SmsTemplateController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-09 10:54
 **/
@RestController
@RequestMapping("/msg/smsTemplate/v1")
public class SmsTemplateController {

    @Resource
    private ISmsTemplateService smsTemplateServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息模板列表")
    @PostMapping(value = "/list")
    public List<SmsTemplateVO> list(@RequestBody SmsTemplateQuery query) {
        return smsTemplateServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息模板列表")
    @PostMapping(value = "/listByConfigId/{configId}")
    public List<SmsTemplateVO> listByConfigId(@PathVariable("configId") Long configId) {
        return smsTemplateServiceImpl.listByConfigId(configId);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "缺省配置的有效消息模板分页查询")
    @PostMapping(value = "/listEffectTemplateByDefaultConfig")
    public List<SmsTemplateVO> listEffectTemplateByDefaultConfig() {
        return smsTemplateServiceImpl.listEffectTemplateByDefaultConfig();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息模板参数列表")
    @PostMapping(value = "/listSmsTemplateParam/{templateId}")
    public List<SmsTemplateParamVO> listSmsTemplateParam(@PathVariable("templateId") Long templateId) {
        return smsTemplateServiceImpl.listSmsTemplateParam(templateId);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息模板有效分页查询")
    @PostMapping(value = "/effectList")
    public List<SmsTemplateVO> effectList(@RequestBody SmsTemplateQuery query) {
        query.setPublishStatus(PublishStatusEnum.ENABLE.getValue());
        return smsTemplateServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "消息模板新增")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) SmsTemplateParam smsTemplateParam) {
        return smsTemplateServiceImpl.add(smsTemplateParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "消息模板修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) SmsTemplateParam smsTemplateParam) {
        return smsTemplateServiceImpl.modify(smsTemplateParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息模板查看")
    @PostMapping(value = "/view/{id}")
    public SmsTemplateVO view(@PathVariable("id") Long id) {
        return smsTemplateServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息模板查看")
    @PostMapping(value = "/viewByCode/{id}")
    public SmsTemplateVO viewByCode(@PathVariable("code") String code) {
        return smsTemplateServiceImpl.queryTemplateByCode(code);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "消息模板启用/禁用")
    @PostMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus( @PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return smsTemplateServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "消息模板删除")
    @PostMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return smsTemplateServiceImpl.del(id);
    }
}
